import { createKey, getKey } from "@/utils/api";
import { createSlice } from "@reduxjs/toolkit";

const loginSlice = createSlice({
    name: 'loginSlice',
    initialState: {
        /* Login登录界面是否隐藏 */
        hidden: false,
        /* key钥匙 */
        key: '',
        /* 二维码地址 */
        loginPic: '',
    },
    reducers: {
        changeHidden(state, action) {
            state.hidden = !state.hidden
        },
        getKey(state, action) {

        }
    },
    extraReducers: (builder) => {
        builder.addCase(createKey.fulfilled, (state, action) => {
            if (action.payload) {
                state.loginPic = action.payload.qrimg
                state.key = action.payload.key
            }
        })
    }
})

export const { changeHidden } = loginSlice.actions

export const { reducer: loginReducer } = loginSlice

